﻿using System;
using System.Linq.Expressions;

namespace NMapper.Utils
{
    public class ExpressionReplacer : ExpressionVisitor
    {
        private Func<Expression, Expression> replacer;

        public ExpressionReplacer(Func<Expression, Expression> replacer)
        {
            this.replacer = replacer;
        }

        public override Expression Visit(Expression node)
        {
            return replacer(node) ?? base.Visit(node);
        }
    }
}